﻿// Necroz project team © <2015> <ArchLord2EMU>
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Author:Sagara
// Date:2015-09-14-21:34

using AL2Game.Interfaces;
using AL2Game.Network;
using AL2Game.Network.Frames.Send;
using ArchLord2Commons.IoC;
using NLog;

namespace AL2Game.Services
{
    public class AuthorizeService : IAuthorizeService
    {
        private static readonly Logger Log = LogManager.GetCurrentClassLogger();

        public void AuthorizeAction(string token, Al2Connection client)
        {
            var accountData = Global.GetMember<ILsService>().AccountInfo(token);

            if (accountData != null)
            {
                client.AccountInfo = accountData;

                if (!LoginServicePipeService.Online.ContainsKey(accountData.Id))
                     LoginServicePipeService.Online.TryAdd(accountData.Id, accountData);

                new SfUnk1().Send(client, 1); //gag
                new SfUnk2().Send(client, 1); //gag
                new SfUnk3().Send(client, 1); //gag
                return;
            }

            client.Disconnect();

            Log.Error($"Not found account data by token: {token}");
        }
        public void Initilize()
        {
            
        }

        public void Release()
        {
            
        }
    }
}